package com.seven.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;

import com.seven.entity.Worker;
import com.seven.service.AWorkerService;

@WebServlet("/worker")
public class AWorkerServlet extends BaseServlet{

    AWorkerService workerService = new AWorkerService();


    public void login(HttpServletRequest request, HttpServletResponse response) throws IOException {
        PrintWriter out = response.getWriter();
        String users_username = request.getParameter("users_username");
        String users_password = request.getParameter("users_password");

        System.out.println(users_username+"==============="+users_password);
        Worker worker = new Worker();
        worker.setWorker_username(users_username);
        worker.setWorker_password(users_password);
        Worker user = workerService.selectByWorker_username(worker);
        System.out.println("============"+user);
        String re="";
        if (user!=null){
            ObjectMapper mapper = new ObjectMapper();
            re ="{\"state\":\"ok\",\"worker\":"+mapper.writeValueAsString(user)+"}";
        }else {
            re ="{\"state\":\"密码错误\"}";
        }
        System.out.println(re);
        out.write(re);
        out.close();
    }

}
